<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['setting']=$this->plugin_setting('basic');
if($_RQ['op']=='main'){
	
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	//查询所有订单
	$params=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}
	$list=pdo_getall('jy_weishop_cutprice_order',$params,'','','createtime desc');
	if($list){
		foreach($list as &$item){
			$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
			$act=pdo_get('jy_weishop_cutprice_act',array('id'=>$item['actid'],'uniacid'=>$_SESSION['uniacid']));
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']));
			$images=json_decode($act['images'],true);
		
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			$item['image']=$images['0'];
			$item['act']=$act;
			$item['member']=$member;
			$item['goods']=$goods;
			
		}
	}
	$return['list']=$list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
	exi('订单不存在，请重新选择','error');
	}
	$order=pdo_get('jy_weishop_cutprice_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//用户信息
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['mid']));
	//活动信息
	$order['act']=pdo_get('jy_weishop_cutprice_act',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['actid']));	
	$order['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['goodsid']));	
	//地址信息
	$address=pdo_get('core_address',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['addressid']));	
	$pcd=json_decode($address['pcd'],true);
	$address['address']=$pcd['province'].$pcd['city'].$pcd['district'].$address['address'];
	//状态
	if($order['status']==1){
		$zhuangtai='待发货';
	}elseif($order['status']==2){
		$zhuangtai='已发货';
	}
	elseif($order['status']==3){
		$zhuangtai='已收货';
	}
	elseif($order['status']==4){
		$zhuangtai='已完成';
	}else{
		$zhuangtai='待付款';
	}
	$order['address']=$address;
	$return['order']=$order;
	$return['zhuangtai']=$zhuangtai;
	$return['member']=$member;
	exi($return);
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_delete('jy_weishop_cutprice_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除订单成功');
}
if($_RQ['op']=='receive'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_update('jy_weishop_cutprice_order',array('status'=>3),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('收货成功');
}
if($_RQ['op']=='pay'){
	$post=get_postdata();
	if(!$post['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_weishop_cutprice_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['id']));
	//支付
	$params['fee']=$order['price'];
	$params['title']='降价拍订单';
	$params['id']=$order['id'];
	$params['plugin']='jy_weishop_cutprice';
	$params['back_url']='jy_weishop_cutprice/create/payresult';
	$payid=cfc('pay')->create_pay_order($params);	
	$return['payid']=$payid;
	$return['id']=$order['id'];
	exi($return);
}
